package com.wuzy.core.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.wuzy.core.pojo.SysUser; 
public class LoginInterceptor implements HandlerInterceptor{
	private final Logger log=Logger.getLogger(LoginInterceptor.class);
	private final String SYSUSER="sysUser";
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
		//log.info("****拦截器*****LoginInterceptor***afterCompletion**********************");
		
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
			throws Exception {
		//log.info("****拦截器*****LoginInterceptor***postHandle***************************");
		
	}

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		log.info("****拦截器*****LoginInterceptor***preHandle******start**************************");
		SysUser sysUser=(SysUser)request.getSession().getAttribute(SYSUSER);
		if(sysUser!=null){
			log.info("****拦截器*****LoginInterceptor***preHandle******start******true****************");
			log.info("---*******sysUser:"+sysUser.getAccount()+"password:"+sysUser.getPassword());
			return true;
		}
		response.sendRedirect("login");
		log.info("****拦截器*****LoginInterceptor***preHandle******start****false*****************");
		return false;
	}

}